{% extends "personal_center/base.html" %}

{% block page_link %}
    {#    <script src="../../static/administrative/js/car_apply_detail.js"></script>#}
    <link rel="stylesheet" href="../../static/technological/css/style.css">

{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }

        .add_background {
            background: #A9A9A9;
        }
        tr {
            height: 35px;
        }
        td {
            padding-right: 5px;outline: none;height: 40px;
        }
        th {
            text-align: center;
        }
        .file {
            position: relative;display: inline-block;background: #D0EEFF;border: 1px solid #99D3F5;border-radius: 4px;padding: 4px 12px;overflow: hidden;color: #1E88C7;text-decoration: none;text-indent: 0;line-height: 20px;
        }
        .file input {
            position: absolute;font-size: 100px;right: 0;top: 0;opacity: 0;
        }
        .file:hover {
            background: #AADFFD;border-color: #78C3F3;color: #004974;text-decoration: none;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
            <a href="#" style="color: #0b0b0b;">
                <i class="iconfont icon-faqi"></i>
                <a href="javascript:;" style="color: #0b0b0b;"> 新增申请</a>
            </a>
        </div>
        <div style="height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button" style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;" onclick="save_data()">
                保存
            </button>
        </div>

        <div style="width: 15%;height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button" style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;" onclick="submit_data()">
                提交
            </button>
        </div>
    </div>
    <hr>

    <div style="width: 100%;height: 95%;overflow: auto;">
        <div id="menu_from" style="width: 100%;height: 100%;color: #2C3E50;display: inline-block;vertical-align: top;background: white;">
            <div style="width: 100%;height: 90%;display: inline-block;vertical-align: center;">
                <div style="width: 95%;margin-left: 2.5%;">
                    <table style="width: 100%;margin-top: 20px;">
                        <tr style="width: 100%;">
                            <td colspan="4" style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;border: #cfcfcf solid 1px;text-align: center;">
                                <h3 id="form_name" style="letter-spacing: 8px;">招标采购项目审批表</h3>
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td colspan="4" style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #F5F5F5;border: #cfcfcf solid 1px;border-top: none;">基本信息</td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 2px;">
                                申&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;人
                            </td>
                            <td id="apply_user" style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;">{{ realname }}</td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.2px;">
                                联系电话
                            </td>
                            <td style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;">{{ Telephone }}</td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.2px;">
                                申&nbsp;&nbsp;&nbsp;请&nbsp;&nbsp;&nbsp;部&nbsp;&nbsp;&nbsp;门
                            </td>
                            <td id="department" style="width: 35%;border: #cfcfcf solid 0.5px;padding-left: 0.5%;line-height: 35px;">{{ department }}</td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.2px;">
                                申请时间
                            </td>
                            <td id="applicat_time" style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;">{{ applicat_time }}</td>
                        </tr>
                        <tr style="width: 100%;">
                            <td colspan="4" style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #F5F5F5;border: #cfcfcf solid 1px;border-top: none;">申请详情</td>
                        </tr>
                        <tr style="width: 100%;">
                            <td rowspan="2" style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.2px;">
                                项&nbsp;&nbsp;&nbsp;目&nbsp;&nbsp;&nbsp;名&nbsp;&nbsp;&nbsp;称
                            </td>
                            <td rowspan="2" id="ApplicationReason" style="width: 35%;border: #cfcfcf solid 0.5px;padding-left: 0.5%;line-height: 35px;" contenteditable="true"></td>
                            <td rowspan="2" style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.2px;">
                                采购类别
                            </td>
                            <td id="" style="width: 35%;border: #cfcfcf solid 0.5px;line-height: 35px;padding-left: 0.5%;">
                                <select name="" id="categories" style="width: 100%;outline: none;height: 100%;border: none;">
                                    <option value="0">请选择采购类型</option>
                                    <option value="1">工程类</option>
                                    <option value="2">货物类</option>
                                    <option value="3">服务类</option>
                                </select>
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 35%;border: #cfcfcf solid 0.5px;line-height: 35px;padding-left: 0.5%;color: red;">
                                采购类别为服务类项目，因合同到期重新招标采购的，请上传原合同;
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.2px;">
                                预&nbsp;算&nbsp;金&nbsp;额(元)
                            </td>
                            <td id="budget_amount" style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;" onblur="financial_format()" contenteditable="true"></td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.2px;">
                                经费来源
                            </td>
                            <td style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;">
                                <select name="" id="source" style="width: 100%;height: 100%;outline: none;border: none;">
                                    <option value="0">请选择经费来源</option>
                                    <option value="1">单位资金</option>
                                    <option value="2">财政拨款</option>
                                </select>
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 2.2px;">
                                项&nbsp;目&nbsp;负&nbsp;责&nbsp;人
                            </td>
                            <td id="project_leader" style="width: 35%;border: #cfcfcf solid 0.5px;padding-left: 0.5%;line-height: 35px;" contenteditable="true"></td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.2px;">
                                联系电话
                            </td>
                            <td id="telephone" style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;" contenteditable="true"></td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                技术咨询联系人
                            </td>
                            <td id="contact_person" style="width: 35%;border: #cfcfcf solid 0.5px;padding-left: 0.5%;line-height: 35px;" contenteditable="true"></td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.2px;">
                                联系电话
                            </td>
                            <td id="contact_telephone" style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;" contenteditable="true"></td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 3.2px;">
                                立项通过会议
                            </td>
                            <td style="width: 35%;border: #cfcfcf solid 0.5px;padding-left: 0.5%;line-height: 35px;">
                                <select name="" id="project_meeting" style="width: 100%;height: 100%;border: none;outline: none;">
                                    <option value="0">请选择立项会议</option>
                                    <option value="1">院长办公会</option>
                                    <option value="2">党委会</option>
                                </select>
                            </td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                纪要编号
                            </td>
                            <td style="width: 35%;border: #cfcfcf solid 0.5px;padding-left: 0.5%;line-height: 35px;">
                                〔<input id="minutes_number_year" type="text" style="width: 80px;border: none;outline: none;border-bottom: #999999 solid 1px;text-align: center;height: 25px;">〕<input type="text" id="minutes_number_number" style="height: 25px;text-align: center;width: 80px;border: none;outline: none;border-bottom: #999999 solid 1px;">号第<input type="text" id="topic_number" style="height: 25px;text-align: center;width: 80px;border: none;outline: none;border-bottom: #999999 solid 1px;">个议题
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 4px;">
                                金额超过3万
                            </td>
                            <td colspan="3" style="width: 85%;border: #cfcfcf solid 0.5px;padding-left: 0.5%;line-height: 35px;">
                                <input type="radio" value="1" name="amount_conditions"> 是
                                <input type="radio" value="0" name="amount_conditions" style="margin-left: 20px;"> 否
                            </td>
                        </tr>
                    </table>
                    <table style="width: 100%;">
                        <thead>
                            <tr style="width: 100%;">
                                <td colspan="6" style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #F5F5F5;border: #cfcfcf solid 1px;border-top: none;">
                                    上传附件
                                    <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                                        上传文件
                                        <input type="file" name="party_main_body" id="party_main_body"
                                               onchange="upload_accessory('file1', 'party_main', 'party_main_body')">
                                    </a>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    文件名称
                                </td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    文件大小
                                </td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    上传时间
                                </td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    上传人员
                                </td>
                                <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作
                                </td>
                            </tr>
                        </thead>
                        <tbody style="overflow: auto;" id="party_main"></tbody>
                    </table>
                    <table style="width: 100%;">
                        <tr style="width: 100%;">
                            <td colspan="6" style="width: 100%;border: #cfcfcf solid 0.5px;height: 35px;padding-left: 1%;border-top: none;color: red;">
                                附件备注：</br>1、项目立项通过的会议纪要；</br>
                                     2、采购需求（设施设备技术性能参数或服务内容及要求或工程概况和内容）；</br>
                                     3、市场调研报告等；</br>4、服务类项目原合同;
                            </td>

                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script type="text/javascript" src="../../static/public_file/other/jquery.js"></script>
    <script src="../../static/administrative/layDate-v5.0.9/laydate/laydate.js"></script> <!-- 改成你的路径 -->

    <script type="text/javascript">
        window.onload = function () {
            document.getElementById("sponsor").className = "add_class";
            document.getElementById("personage").className = "add-nav-active";
            $('input[name="custom_made"]').click(function() { // 点击复选框时执行
                $('input[name="custom_made"]').not(this).prop('checked', false); // 将其他复选框取消选中状态
            });
        };

        const uuid = '{{ uuid }}'

        function submit_data() {
            var form = new FormData();
            var ApplicationReason = document.getElementById("ApplicationReason").innerText;         // 项目名称
            var categories = document.getElementById("categories").value;                                   // 采购类别
            var budget_amount = document.getElementById("budget_amount").innerText;             // 预算金额
            var source = document.getElementById("source").value;                                   // 经费来源
            var project_leader = document.getElementById("project_leader").innerText;           //项目负责人
            var telephone = document.getElementById("telephone").innerText;                         //联系电话
            var contact_person = document.getElementById("contact_person").innerText;               // 技术咨询联系人
            var contact_telephone = document.getElementById("contact_telephone").innerText;                 // 技术咨询联系电话
            var project_meeting = document.getElementById("project_meeting").value;                                   // 立项会议
            var minutes_number_year = document.getElementById("minutes_number_year").value;                                   // 立项会议年份
            var minutes_number_number = document.getElementById("minutes_number_number").value;                                   // 立项会议编号
            var topic_number = document.getElementById("topic_number").value;                                               // 第几个议题
            var amount_conditions = $("input[type=radio][name=amount_conditions]:checked").val();           // 是否超过三万

            var administrative_table = document.getElementById('party_main');
            if (!administrative_table.children.length) {
                alert("请上传附件！");
                return false
            }
            if (!ApplicationReason) {
                alert("请输入项目名称！");
                return false
            }
            if (categories === '0') {
                alert("请选择采购类别！");
                return false
            }
            if (!budget_amount) {
                alert("请输入预算金额！");
                return false
            }
            if (source === '0') {
                alert("请选择经费来源！");
                return false
            }
            if (!project_leader) {
                alert("请输入项目负责人！");
                return false
            }
            if (!contact_person) {
                alert("请输入技术咨询联系人！");
                return false
            }
            if (!minutes_number_year) {
                alert("请输入立项会议年份！");
                return false
            }
            if (!minutes_number_number) {
                alert("请输入立项会议编号！");
                return false
            }
            if (!topic_number) {
                alert("请输入第几个议题！");
                return false
            }
            if (!amount_conditions) {
                alert("请选择金额是否超过3万！");
                return false
            }

            form.append('ApplicationReason', ApplicationReason);
            form.append('categories', categories);
            form.append('budget_amount', budget_amount);
            form.append('source', source);
            form.append('project_leader', project_leader);
            form.append('telephone', telephone);
            form.append('contact_person', contact_person);
            form.append('contact_telephone', contact_telephone);
            form.append('project_meeting', project_meeting);
            form.append('minutes_number_year', minutes_number_year);
            form.append('minutes_number_number', minutes_number_number);
            form.append('topic_number', topic_number);
            form.append('amount_conditions', amount_conditions);
            form.append('uuid', uuid);
            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/logistics/BiddingProcurementProjectIndex.html", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("创建成功");
                            window.location = "/logistics/BiddingProcurementProjectList.html";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
            };
        }

        function save_data() {
            var form = new FormData();
            var ApplicationReason = document.getElementById("ApplicationReason").innerText;         // 项目名称
            var categories = document.getElementById("categories").value;                                   // 采购类别
            var budget_amount = document.getElementById("budget_amount").innerText;             // 预算金额
            var source = document.getElementById("source").value;                                   // 经费来源
            var project_leader = document.getElementById("project_leader").innerText;           //项目负责人
            var telephone = document.getElementById("telephone").innerText;                         //联系电话
            var contact_person = document.getElementById("contact_person").innerText;               // 技术咨询联系人
            var contact_telephone = document.getElementById("contact_telephone").innerText;                 // 技术咨询联系电话
            var project_meeting = document.getElementById("project_meeting").value;                                   // 立项会议
            var minutes_number_year = document.getElementById("minutes_number_year").value;                                   // 立项会议年份
            var minutes_number_number = document.getElementById("minutes_number_number").value;                                   // 立项会议编号
            var topic_number = document.getElementById("topic_number").value;                                               // 第几个议题
            var amount_conditions = $("input[type=radio][name=amount_conditions]:checked").val();           // 是否超过三万

            form.append('ApplicationReason', ApplicationReason);
            form.append('categories', categories);
            form.append('budget_amount', budget_amount);
            form.append('source', source);
            form.append('project_leader', project_leader);
            form.append('telephone', telephone);
            form.append('contact_person', contact_person);
            form.append('contact_telephone', contact_telephone);
            form.append('project_meeting', project_meeting);
            form.append('minutes_number_year', minutes_number_year);
            form.append('minutes_number_number', minutes_number_number);
            form.append('topic_number', topic_number);
            form.append('amount_conditions', amount_conditions);
            form.append('uuid', uuid);
            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/logistics/BiddingProcurementProjectDraft.html", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("保存成功");
                            window.location = "/logistics/BiddingProcurementProjectList.html";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
            };
        }

        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', uuid)
            form.append('source', 'ddzy')
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";
                    td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
                    t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                tr = document.createElement("tr");td1 = document.createElement("td");td2 = document.createElement("td");td3 = document.createElement("td");td4 = document.createElement("td");td5 = document.createElement("td");td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);t_table.appendChild(tr);
            }
        }
        
        function formatMonenyNumber(number, toFixed = 2) {
            let str = [];
            if (!number) return 0
            if (typeof number === "number") number = String(number)
            let tempNumber = number.split('.');
            number = tempNumber[0]
            if (number.length <= 3) {
                if (tempNumber[1]) {
                    var decimils = tempNumber[1].slice(0, toFixed);
                if (decimils.length === 1){
                    decimils = decimils + "0";
                }
                number += '.' + decimils;
                }else {
                    number += '.00'
                }
                return number
            }
            number.split('').reverse().forEach((item, index) => {
                if (index !== 0 && index % 3 === 0) {
                    str.push(',', item)
                } else {
                    str.push(item)
                }
            })
            number = str.reverse().join('')
            if (tempNumber[1]) {
                var decimils = tempNumber[1].slice(0, toFixed);
                if (decimils.length === 1){
                    decimils = decimils + "0";
                }
                number += '.' + decimils;
            }else {
                 number += '.00'
            }
            return number;
        }
        
        function financial_format() {
            document.getElementById('budget_amount').innerText = formatMonenyNumber(document.getElementById('budget_amount').innerText.replace(',', '').replace(',', '').replace(',', ''))
        }

        function RemoveTr(_this, tbody_id, wj_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i=0; i<table.children.length; i++){
                table.children[i].children[0].innerHTML=i+1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id="+String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }
    </script>
{% endblock %}



